package cn.sccl.dirms.topo.discovery.service.impl;

import cn.sccl.common.dao.BaseDAO;
import cn.sccl.common.database.DataBase;
import cn.sccl.common.service.impl.BaseManagerImpl;
import cn.sccl.dirms.topo.discovery.dao.DiscoverTaskScheduleDAO;
import cn.sccl.dirms.topo.discovery.model.DiscoverTaskSchedule;
import cn.sccl.dirms.topo.discovery.service.DiscoverTaskScheduleManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.ArrayList;
import java.util.List;

/**
* 自动发现规则 的Manager实现类
* Created by _minus on 2017-09-25.
*/
@Service
public class DiscoverTaskScheduleManagerImpl extends BaseManagerImpl<DiscoverTaskSchedule> implements DiscoverTaskScheduleManager{

    @Autowired
    private DiscoverTaskScheduleDAO discoverTaskScheduleDAO;

    public DiscoverTaskScheduleDAO getDiscoverTaskScheduleDAO(){
        return discoverTaskScheduleDAO;
    }

    @Override
    public BaseDAO<DiscoverTaskSchedule> getBaseDAO(){
        return getDiscoverTaskScheduleDAO();
    }

    @Autowired
    DataBase dataBase ;

    @Override
    public DataBase getDataBase(){return this.dataBase ;}


    @Override
    public DiscoverTaskSchedule findDiscoverTaskScheduleByTaskId(String id) {
        StringBuffer sql = new StringBuffer();
        DiscoverTaskSchedule result = new DiscoverTaskSchedule();
        sql.append("select s.* from t_topo_discover_schedule s where s.delete_flag = 0 and s.task_id = ? ");

        if (!StringUtils.isEmpty(id)){
            List params = new ArrayList<Object>();
            params.add(id);

            List<DiscoverTaskSchedule> taskSchedules =  getDataBase().query4Model(sql.toString(),DiscoverTaskSchedule.class,params.toArray()) ;
            if (taskSchedules != null && taskSchedules.size() ==1 ) {
                result =  taskSchedules.get(0);
            }
        }
        return result;
    }
}